package tutorial;

import gui.RiskGUI;

import org.eclipse.swt.widgets.Shell;

public class Tutorial {

	public static final int Tutorialwidth = 219;
	private Shell parent;
	private TutorialWindow[] steps;
	private int currStep = -1;
	private boolean ended; 

	public Tutorial(Shell parent){
		this.parent = parent;
		this.steps = new TutorialWindow[] {
				new StepOne(parent, this),
				new StepTwo(parent, this),
				new StepThree(parent, this),
				new StepFour(parent, this),
				new StepFourTwo(parent, this),
				new StepFive(parent, this),
				new Finish(parent, this),
		};
	}

	public void startTutorial(){
		int gameWidth = RiskGUI.display.getClientArea().width - Tutorial.Tutorialwidth;
		int gameHeight = RiskGUI.display.getClientArea().height;
		parent.setLocation(0, 0);
		parent.setSize(gameWidth, gameHeight);
		parent.setMaximized(false);
		
		StepZero zero = new StepZero(parent, this);
		zero.open();
	}

	public void endTutotial(){
		for(TutorialWindow step : this.steps){
			if(step.getShell() != null)
				step.getShell().dispose();
		}
		this.ended = true;
		parent.setMaximized(true);
	}

	public void nextStep(){
		if(currStep == -1){
			++currStep;
			steps[0].open();
		} else {
			if(!steps[currStep].getShell().isDisposed())
				steps[currStep].getShell().setVisible(false);
			++currStep;
			steps[currStep].open();
		}
	}

	public void prvStep(){
		System.out.println(currStep);
		if(!steps[currStep].getShell().isDisposed())
			steps[currStep].getShell().setVisible(false);
		--currStep;
		if(currStep != -1)
			steps[currStep].open();
		else{
			currStep = 0;
			steps[currStep].open();
		}
	}

	/**
	 * @return the ended
	 */
	public boolean isEnded() {
		return ended;
	}
}
